package com.cskaoyan.service.wx.sl;

import com.cskaoyan.bean.Feedback;
import com.cskaoyan.bean.User;
import com.cskaoyan.mapper.FeedbackMapper;
import com.cskaoyan.mapper.UserMapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;

@Service
public class WxFeedbackServiceImpl implements WxFeedbackService {

    @Autowired
    FeedbackMapper feedbackMapper;
    @Autowired
    UserMapper userMapper;
    //添加反馈
    @Override
    public int footprintList(Feedback feedback) {
        feedback.setAddTime(new Date());
        feedback.setUpdateTime(new Date());
        //根据请求头获取userid，然后查username
        User usere = (User) SecurityUtils.getSubject().getPrincipal();
        Integer usereId = usere.getId();
        User user = userMapper.selectByPrimaryKey(usereId);
        String username = user.getUsername();
        Byte sta = user.getStatus();
        int status = sta;
        String pic = user.getAvatar();
        Boolean deleted = user.getDeleted();
        //传入反馈表
        feedback.setUserId(usereId);
        feedback.setUsername(username);
        feedback.setStatus(status);
        feedback.setDeleted(deleted);
        String[] picUrls = {pic};
        feedback.setPicUrls(picUrls);
        //插入反馈表
        int i = feedbackMapper.insertSelective(feedback);
        return i;
    }

}
